import com.alibaba.fastjson.JSONObject;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/ServletZhuce")
public class ServletZhuce extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置编码
        request.setCharacterEncoding("utf-8");
//获取请求参数的值
        String username = request.getParameter("username");
        System.out.println(username);
        JSONObject jsonObject=new JSONObject();
        //设置响应的格式  表示响应信息传过去的格式为hson格式   大的格式/小的格式
        response.setContentType("application/json;charset=utf-8");
        if ("zhangsan".equals(username)) {
//表明用户名zhangsan存在
            jsonObject.put("message",true);
            response.getWriter().write(JSONObject.toJSONString(jsonObject));
        }
    }
}
